<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <script src="js/vue.js"></script>
  <script src="js/axios.min.js"></script>
  <title>用户信息 - 冈勿ffub饰品交易平台</title>
  <style>
    body {
      background-color: #121212;
      color: #e0e0e0;
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      margin: 0;
      padding: 0;
      position: relative;
      min-height: 100vh;
      background-image: url('images/csgo2.jpg'); /* 设置背景图 */
      background-size: cover; /* 确保背景图覆盖整个页面 */
      background-position: center center; /* 背景图居中 */
      background-attachment: fixed; /* 背景图固定，页面滚动时不会动 */
    }

    .container {
      max-width: 1000px;
      margin: 80px auto 20px auto;
      background-color: rgba(30, 30, 30, 0.8); /* 设置半透明背景 */
      padding: 20px 30px;
      border-radius: 8px;
      box-shadow: 0 0 12px #222;
    }

    h1 {
      text-align: center;
      color: #aa9bf9;
      margin-bottom: 18px;
    }

    .info-item {
      margin-bottom: 14px;
      font-size: 15px;
    }

    .info-item span {
      color: #aaa;
    }

    .avatar {
      display: block;
      width: 80px;
      height: 80px;
      margin: 0 0 15px 460px; /* 上右下左，左边距20px */
      border-radius: 50%;
      object-fit: cover;
    }

    .back-btn, .logout-btn {
      position: fixed;
      top: 20px;
      background-color: #aa9bf9;
      color: #121212;
      padding: 8px 16px;
      font-weight: 700;
      font-size: 14px;
      border-radius: 6px;
      cursor: pointer;
      border: none;
      transition: background-color 0.3s ease;
      z-index: 1000;
    }
    .back-btn { left: 20px; }
    .logout-btn { right: 20px; }
    .back-btn:hover, .logout-btn:hover {
      background-color: #8c7ee6;
    }

    /* 用户信息区域布局 */
    .user-info-bar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-wrap: wrap;
    }

    .user-info-left {
      flex: 1;
      min-width: 280px;
    }

    .user-info-right {
      margin-top: 12px;
    }

    .order-btn {
      background-color: #aa9bf9;
      color: #121212;
      padding: 10px 18px;
      font-weight: 700;
      font-size: 14px;
      border-radius: 6px;
      border: none;
      cursor: pointer;
      transition: background-color 0.3s ease;
    }

    .order-btn:hover {
      background-color: #8c7ee6;
    }

    /* 饰品样式 */
    #items-container {
      margin-top: 40px;
      background-color: #222;
      border-radius: 8px;
      box-shadow: 0 0 10px #111;
      padding: 20px;
    }

    .equipment-grid {
      display: flex;
      flex-wrap: wrap;
      gap: 16px;
      justify-content: center;
    }

    .equipment-card {
      background-color: rgba(0, 0, 0, 0.7); /* 设置黑色半透明背景 */
      border-radius: 8px;
      padding: 12px;
      width: 160px;
      text-align: center;
      color: #ccc;
      box-shadow: 0 2px 8px #000;
      transition: box-shadow 0.3s ease;
    }

    .equipment-card:hover {
      box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    }

    .equipment-card img {
      width: 100%;
      height: 120px;
      object-fit: cover;
      border-radius: 5px;
      margin-bottom: 6px;
    }

    /* 广告样式 */
    .advertisement {
      position: fixed;
      top: 50%;
      transform: translateY(-50%);
      width: 200px;
      height: 300px;
      background-color: rgba(0, 0, 0, 0.8);
      color: #fff;
      box-shadow: 0 0 12px rgba(0, 0, 0, 0.5);
      z-index: 999;
    }

    .advertisement.left {
      left: 0;
    }

    .advertisement.right {
      right: 0;
    }

    .advertisement img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 8px;
    }

    .close-btn {
      position: absolute;
      top: 5px;
      right: 5px;
      background-color: rgba(255, 255, 255, 0.7);
      color: #121212;
      border: none;
      font-size: 16px;
      padding: 5px 10px;
      cursor: pointer;
      border-radius: 50%;
      transition: background-color 0.3s;
      width: 25px;
      height: 25px;
      text-align: center;
      line-height: 15px;
    }

    .close-btn:hover {
      background-color: #ff4747;
    }
  </style>
</head>
<body>

<button class="back-btn" id="backBtn">返回首页</button>
<button class="logout-btn" id="logoutBtn">登出</button>

<!-- 广告弹窗 -->
<div v-if="showLeftAd" class="advertisement left">
  <button class="close-btn">x</button>
  <img src="images/驰星.jpg" alt="左侧广告" />
</div>
<div v-if="showRightAd" class="advertisement right">
  <button class="close-btn">x</button>
  <img src="images/gg3.gif" alt="右侧广告" />
</div>

<!-- Vue 主容器 -->
<div class="container" id="app">
  <h1>用户信息</h1>

  <div class="user-info-bar">
    <div class="user-info-left">
      <img class="avatar" :src="user.userAvatar" alt="用户头像" v-if="user.userAvatar" />
      <div class="info-item"><span>用户名：</span>{{ user.userName }}</div>
      <div class="info-item"><span>注册时间：</span>{{ formatDate(user.createTime) }}</div>
      <div class="info-item"><span>状态：</span>{{ user.status === 0 ? '正常' : '其他' }}</div>
    </div>
    <div class="user-info-right">
      <button class="order-btn" @click="goToOrder">我的订单</button>
    </div>
  </div>

  <!-- 饰品展示区域 -->
  <div id="items-container">
    <h2 style="text-align:center; color:#aa9bf9;">拥有的饰品</h2>
    <div v-if="equipmentList.length === 0" style="text-align:center; font-size:18px; color:#aaa;">
      暂无饰品
    </div>

    <div v-else class="equipment-grid">
      <a v-for="item in equipmentList"
         :key="item.equipmentId"
         :href="'inventory_detail.html?equipmentId=' + item.equipmentId"
         class="equipment-card">
        <img :src="item.equipmentImage" alt="饰品图片" />
        <div>{{ item.equipmentName }}</div>
        <div>价格：¥{{ item.equipmentPrice }}</div>
      </a>
    </div>
  </div>
</div>

<script>
  new Vue({
    el: '#app',
    data: {
      user: {},
      equipmentList: [],
      showLeftAd: true,  // 控制左侧广告弹窗的显示
      showRightAd: true, // 控制右侧广告弹窗的显示
    },
    mounted() {
      const userId = localStorage.getItem('userId');
      if (!userId) {
        alert('请先登录');
        window.location.href = 'login.html';
        return;
      }

      // 获取用户信息
      axios.get(`/ffub/users/${userId}`).then(res => {
        if (res.data.code === 200) {
          this.user = res.data.data;
          this.getAllequipmentsByuserId(userId);
        } else {
          alert('获取用户信息失败');
        }
      }).catch(() => {
        alert('服务器请求失败');
      });

      // 登出按钮事件
      document.getElementById('logoutBtn').addEventListener('click', () => {
        localStorage.removeItem('userId');
        localStorage.removeItem('userName');
        alert('已登出');
        window.location.href = 'main.html';
      });

      // 返回首页按钮事件
      document.getElementById('backBtn').addEventListener('click', () => {
        window.location.href = 'main.html';
      });
    },
    methods: {
      // 获取用户饰品列表
      getAllequipmentsByuserId(userId) {
        axios.get(`/ffub/equipment/userId/${userId}`)
                .then(response => {
                  if (response.data.code === 200) {
                    this.equipmentList = response.data.data;
                  } else {
                    alert("获取饰品失败");
                  }
                })
                .catch(error => {
                  console.error("请求失败:", error);
                });
      },
      // 格式化日期
      formatDate(datetime) {
        if (!datetime) return '';
        return new Date(datetime).toLocaleString();
      },
      // 跳转到订单页面
      goToOrder() {
        window.location.href = 'myorder.html';
      }
    }
  });
</script>

</body>
</html>
